package com.wondream.myframework.thread;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;

public class ThreadConsistencyTest {
    int count = 10000;
    // 取钱方法
    void getMoney(int money){
        if(count==0){
            throw new RuntimeException("余额为0");
        }
        count-=money;
    }

    class Person implements Runnable {
        @Override
        public void run() {
            while (true) {
                getMoney(1000);
                logger.info("当前余额："+count);
                Thread.yield();
            }
        }
    }

    Log logger = LogFactory.getLog(ThreadConsistencyTest.class);

    @Test
    public void execute(){
        Thread person1 = new Thread(new Person());
        Thread person2 = new Thread(new Person());
        person1.start();
        person2.start();
    }
}
